package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * 图片资源控制器
 */
@RestController
@RequestMapping("/images")
public class ImagesController {

    @PostMapping
    public Map upload(MultipartFile file){

        Map <String, Object> map = new HashMap<>();

            String upload = null;
            try {
//                upload = UploadUtil.upload(file, "/upload");
                upload = UploadUtil.uploadQiniu(file);
                map.put("url",upload);
                map.put("status",1);
            } catch (Exception e) {
                map.put("status",0);
                map.put("msg","服务器空间不足");
                e.printStackTrace();
            }
        return map;

    }

}
